package com.mtzqc.net

import com.mtzqc.net.config.ParamAssembly
import okhttp3.OkHttpClient
import rxhttp.RxHttpPlugins
import rxhttp.wrapper.annotation.DefaultDomain
import rxhttp.wrapper.ssl.HttpsUtils


object RxConfig {
    @DefaultDomain //设置为默认域名
    @JvmField
    var baseUrl: String = "ddd"

    fun initRxHttp(url: String, debug: Boolean, client: OkHttpClient = okClient()) {
        baseUrl = url
        RxHttpPlugins.init(client)
            .setDebug(debug)
            .setOnParamAssembly(ParamAssembly())
    }

    const val HEADER_DEVICE = "mDevice"
    const val HEADER_LAUNCH = "mLaunchTs"
    const val HEADER_VERSION = "mVersion"
    const val HEADER_REQ = "mReqId"
    const val HEADER_TOKEN = "token"
    fun okClient(): OkHttpClient {
        val sslParams = HttpsUtils.getSslSocketFactory()
        return OkHttpClient.Builder()
            .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager) //添加信任证书
            .hostnameVerifier { _, _ -> true }
            .build()
    }

}